﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using CI.Interfaces;

namespace CI.Organism
{
    /// <summary>Neural cell collection</summary>
    [CollectionDataContract]
    public class NeuronCollection : SynchronizedCollection<INeuron>, INeuronCollection
    {
        /// <summary>
        /// Find the cell with the specifed guid
        /// </summary>
        /// <param name="guid">guid to find</param>
        /// <returns>Cell</returns>
        public INeuron Find(Guid guid)
        {
            return this.FirstOrDefault(neuron => ((ICell)neuron).Guid == guid);
        }

        /// <summary>
        /// do a equals comparison of one cell type to another only comparing the value types, no refference comparisons
        /// </summary>
        /// <param name="cell">cell to compare against</param>
        /// <returns>true if equal value types</returns>
        public bool EqualsValueTypes(ICell cell)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Empty ctor
        /// </summary>
        public NeuronCollection() { }

        /// <summary>
        /// ctor that takes and exisiting colleciton
        /// </summary>
        /// <param name="neuronCollection"></param>
        public NeuronCollection(INeuronCollection neuronCollection)
        {
            // empty array
            var neurons = new INeuron[neuronCollection.Count];
            // copy it to the array
            neuronCollection.CopyTo(neurons, 0);
            // copy it to this array
            foreach (INeuron neuron in neurons)
            {
                Add(neuron);
            }
        }

        /// <summary>
        /// Dump a list of the neurons
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string result = null;

            foreach (INeuron neuron in this)
            {
                result += neuron + Environment.NewLine;
            }

            return result;
        }

    }
}